package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;


/**
 * @author 阿宅
 * @param 登录导航界面
 */
public class FirstActivity extends AppCompatActivity {

    private final String TAG ="FirstActivity";
    private final Handler handler = new Handler();
    private Button btn_intent;
    private Runnable runnable = this::initlogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        //沉浸式状态栏
        if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

        //绑定化控件
        initview();

        //点击跳转后直接跳到主页面
        initskip();

        //等待三秒跳转到主页面
        initwait();
    }

    private void initskip() {
        btn_intent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handler.removeCallbacks(runnable);
                initlogin();
                Log.e(TAG,"initskip()");
            }
        });
    }

    private void initwait() {
        handler.postDelayed(runnable,3000);
        Log.e(TAG,"initwait()");
    }

    private void initlogin() {
        Intent intent = new Intent("com.example.myapplication");
        //Intent intent = new Intent(FirstActivity.this,MainActivity.class);
        startActivity(intent);
        finish();
        Log.e(TAG,"initlogin()");
    }

    private void initview() {
        btn_intent = findViewById(R.id.btn_intent);
    }
}